import React, { useRef, forwardRef, useImperativeHandle } from 'react'
import EditModal from "@/components/common/EditModal";

interface IProps {
    btn: React.ReactNode
    content: React.ReactNode
}

interface IRecentlyModalProps {
    showModal: () => void
    handleCancel: () => void
    handleOk: () => void
}

const RecentlyModal = forwardRef(({ btn, content }: IProps, ref) => {
    const recentlyModalRef = useRef(null)
    const showModal = () => {
        if (recentlyModalRef.current) {
            (recentlyModalRef.current as IRecentlyModalProps).showModal()
        }
    }
    const handleCancel = () => {
        if (recentlyModalRef.current) {
            (recentlyModalRef.current as IRecentlyModalProps).handleCancel()
        }
    }
    const handleOk = () => {
        if (recentlyModalRef.current) {
            (recentlyModalRef.current as IRecentlyModalProps).handleOk()
        }
    }
    useImperativeHandle(ref, () => ({ showModal, handleOk, handleCancel }))
    return (
        <EditModal ref={recentlyModalRef} title={'编辑信息'} btn={btn} footer={null} content={content} />
    )
})

export default RecentlyModal